package com.caiya.controller;

import com.caiya.cart.Res;
import com.caiya.cart.dto.type.CartBrandListDto;
import com.caiya.cart.vo.type.AddCartTypeVo;
import com.caiya.cart.vo.type.CartTypeListVo;
import com.caiya.cart.vo.type.DelTypeVo;
import com.caiya.cart.vo.type.UpdateTypeVo;
import com.caiya.service.CartTypeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2018/11/30 0030.
 */
@RestController
@Api(description = "车型")
@RequestMapping("/api/type")
public class CartTypeController {

    @Autowired
    private CartTypeService cartTypeService;

    @PostMapping(value = "/list")
    @ApiOperation(value = "汽车品牌",notes = "汽车品牌list")
    public Res list(@RequestBody CartTypeListVo cartRequest){
        Res res = null;
        try {
            PageInfo<CartBrandListDto> info = cartTypeService.list(cartRequest);
            res = new Res(info);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "新增",notes = "新增")
    public Res add(@RequestBody AddCartTypeVo addCartTypeVo){
        Res res = null;
        try {
            int i = cartTypeService.add(addCartTypeVo);
            res = new Res(i);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改",notes = "修改")
    public Res update(@RequestBody UpdateTypeVo updateTypeVo){
        Res res = null;
        try {
            int i = cartTypeService.update(updateTypeVo);
            res = new Res(i);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }
    
    @PostMapping(value = "/del")
    @ApiOperation(value = "删除",notes = "删除")
    public Res del(@RequestBody DelTypeVo delTypeVo){
        Res res = null;
        try {
            int i = cartTypeService.del(delTypeVo);
            res = new Res(i);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }
}
